﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataLib.Accounts.Bus;
using System.Data;

namespace Ewts.Production
{
    public partial class ProduceWaitInStorageList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                User curUser = new User();
                curUser = (User)Session["UserInfo"];
              
                ListItem item = new ListItem();
                item.Text = "--请选择--";
                item.Value = "";
                DataLib.BLL.City bllLib = new DataLib.BLL.City();

                // 归属地
                dropBelong.DataSource = bllLib.GetList("flag1 = '01'");
                dropBelong.DataTextField = "cityname";
                dropBelong.DataValueField = "citycode";
                dropBelong.DataBind();
                dropBelong.Items.Insert(0, item);

                // 处理地
                dropGraphics.DataSource = bllLib.GetList("flag1 = '02'");
                dropGraphics.DataTextField = "cityname";
                dropGraphics.DataValueField = "citycode";
                dropGraphics.DataBind();
                dropGraphics.Items.Insert(0, item);
               // dropGraphics.SelectedValue = "";
               
                if (curUser.UserType == "AA")
                {
                    dropGraphics.SelectedItem.Text = curUser.CompanyCity;
                    dropGraphics.Enabled = false;
                }
                else
                {
                    dropGraphics.SelectedItem.Text = "全部";
                }
                bindData();
            }
        }
        protected void bindData()
        {
            string graphicity = "";
            string belongcity = "";
            if (dropGraphics.SelectedItem.Text != "全部")
                graphicity = dropGraphics.SelectedItem.Text;
            else
                graphicity = "";
            if (dropBelong.SelectedItem.Text != "全部")
                belongcity = dropGraphics.SelectedItem.Text;
            else
                belongcity = "";

            DataLib.BLL.Productions bll = new DataLib.BLL.Productions();
            DataTable dt = bll.getProduceWaitInStorageList("", graphicity);
            rept.DataSource = dt;
            rept.DataBind();
        }

        //protected string GetIDtype(string id,string outstatus)
        //{
        //    string str = "";
        //    if (outstatus == "12")
        //    {
        //        str += "<a href='ProduceStorage.aspx?outid=" + id + "'>" + GetHrefOper(outstatus) + "</a>";
        //    }
        //        else if (outstatus == "13")
        //        {
                    
        //        }
        //    else 
        //    {
        //        str += "<a href='ProduceMaterial.aspx?outid=" + id + "'>" + GetHrefOper(outstatus) + "</a>";
        //    }
        //    return str;
        //}


        /// <summary>
        /// 
        /// </summary>
        /// <param name="out_status"></param>
        /// <param name="outid"></param>
        /// <param name="type">0为领料</param>
        /// <returns></returns>
        protected string GetOutStatus(string out_status,string outid, int type)
        {

            //  <a style="color:blue;" <%# GetDisabled(Eval("out_status").ToString()) %> href="ProduceMaterial.aspx?outid=<%# Eval("outs_id") %>">生产领料</a>
          //<a style="color:blue;" <%# GetDisabled(Eval("out_status").ToString()) %> href="ProduceStoragetemp.aspx?outid=<%# Eval("outs_id") %>">生产录入</a>
            string str = "";
            if (type == 0)
            {
                if (out_status == "1" || out_status=="11" || out_status == "12")
                {
                    str = " style='color:blue;' href='ProduceMaterial.aspx?outid=" + outid + "'";
                    
                }
                else
                {
                    str = " style='color:#ccc;'";
                }
            }
            else
            {
                if (out_status=="13" || out_status == "12")
                {
                    str = " style='color:blue;' href='ProduceStorage.aspx?outid=" + outid + "'";
                }
                else
                {
                    str = " style='color:#ccc;'";
                    
                }
            }
            return str;
        }

        /// <summary>
        /// 获取入库单号
        /// </summary>
        /// <param name="outid">出库单id</param>
        /// <returns></returns>
        //public string GetInStorageID(string outid)
        //{
        //    string strinno = "";

        //    System.Data.DataTable dt = new DataLib.BLL.InStorage().GetList("outid=" + outid).Tables[0];
        //    if (dt != null && dt.Rows.Count>0)
        //    {
        //        strinno = dt.Rows[0]["id"].ToString();
        //        DataLib.Model.InStorage inmodel = new DataLib.BLL.InStorage().GetModel(int.Parse(strinno));
        //        strinno = inmodel.wrlno;
        //    }

        //     return strinno;
        //}

        /// <summary>
        /// 根据虚拟Load号取得Load号总重量
        /// </summary>
        /// <param name="vloadnum"></param>
        /// <param name="flag"></param>
        /// <returns></returns>
        //public string GetLoadWeight(string vloadnum,int flag)
        //{
        //    string weight = new DataLib.BLL.StorageData().GetLoadWeight(vloadnum, flag);
        //    return weight;
        //}

        /// <summary>
        /// 根据虚拟Load获取入库所有日期
        /// </summary>
        /// <param name="vLoadNum">虚拟Load号</param>
        /// <param name="flag">0代表正文显示，其他值代表Title，鼠标移上去的提示</param>
        /// <returns></returns>
        //public string GetInStorageDate(string vloadnum, int flag, string outtype, string ins_date)
        //{
        //    if (outtype == "6")
        //    {
        //        return ins_date;
        //    }
        //    else
        //    {
        //        return new DataLib.BLL.StorageData().InStorageDate(vloadnum, flag);
        //    }
        //}

        /// <summary>
        /// 根据出库ID返回当前单号的重量
        /// 
        /// </summary>
        /// <param name="outid"></param>
        /// <param name="flag">0,总重量，1是已入库重量，2是未入库重量</param>
        /// <returns></returns>
        //public string GetOutNoWeight(string outid,int flag)
        //{
        //    string strwt = "0";
        //    decimal waitwt = 0;
        //    DataLib.Model.OutStorage oModel = new DataLib.BLL.OutStorage().GetModel(int.Parse(outid));
        //    if (oModel != null)
        //    {
        //        if (oModel.totalWeight == null)
        //        {
        //            oModel.totalWeight = 0;
        //        }
        //        if (oModel.currentWeight == null)
        //        {
        //            oModel.currentWeight = 0;
        //        }
        //        waitwt =(decimal)oModel.totalWeight - (decimal)oModel.currentWeight;
        //        switch (flag)
        //        {
        //            case 0:
        //                strwt = oModel.totalWeight.ToString();
        //                break;
        //            case 1:
        //                strwt = oModel.currentWeight.ToString();
        //                break;
        //            case 2:
        //                strwt = waitwt.ToString();
        //                break;
        //            default:
        //                break;
        //        }
        //    }
        //    return strwt;
        //}

        protected void dropGraphics_SelectedIndexChanged(object sender, EventArgs e)
        {
            bindData();
        }


        /// <summary>
        /// 
        /// </summary>
        /// <param name="id"></param>
        /// <param name="flag">标识为1取名称，否则 取编码</param>
        /// <returns></returns>
        //public string GetCumByOutID(object id, int flag)
        //{
        //    int outid = int.Parse(id.ToString());
        //    DataLib.Model.OutStorage model = new DataLib.BLL.OutStorage().GetModel(outid);
        //    string cumname = "";
        //    if (model.inDepart == model.belogarea && model.OutDepart != model.graphicCity && model.StorageType != "原料库")
        //    {
        //        cumname = model.OutDepart + model.graphicCity + "库";
        //    }
        //    else if (model.StorageType != "原料库")
        //    {
        //        cumname = model.inDepart + "伟翔";
        //    }
        //    else
        //    {
        //        DataLib.Model.LoadNum lmodel = new DataLib.BLL.LoadNum().GetLoadID(model.VLoadNum);
        //        if (lmodel != null)
        //        {
        //            if (flag == 1)
        //                cumname = new DataLib.BLL.Cumtomer().GetModel((int)lmodel.customerid).companyname;
        //            else
        //                cumname = new DataLib.BLL.Cumtomer().GetModel((int)lmodel.customerid).customercode;
        //        }
        //    }
        //    return cumname;
        //}

    }
}